package com.pillar.response;


import lombok.Data;

/**
 * @author pillar
 * @desc 统一数据返回格式
 * @email: 347637454@qq.com
 * @createDate 2021-01-04 10:39
 */
@Data
public class R<T> {

    private T data;

    private Integer code = 200;

    private String message = "success";

    /**
     * 成功标记
     * @param t
     * @param <T>
     * @return
     */
    public static <T> R<T> success(T t){
        R<T>  r = new R<>();
        r.setData(t);
        return r;
    }

    /**
     * 成功标记
     * @param <T>
     * @return
     */
    public static <T> R<T> success(){
        return new R<>();
    }

    /**
     * 失败
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> R<T> fail(Integer code,String message){
        R<T>  r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

    /**
     * 失败
     * @param message
     * @param <T>
     * @return
     */
    public static <T> R<T> fail(String message){
        R<T>  r = new R<>();
        r.setCode(500);
        r.setMessage(message);
        return r;
    }

}
